package cn.dapeng;

import java.lang.reflect.Constructor;
import java.lang.reflect.Type;

public class ReflectT01 {

    public static void main(String[] args) {

        Person p = new Person();
        p.setGender("男");
        Class<?> pClass = p.getClass();

        Student student = new Student(1, "dapeng");
        Class<?> sClass = student.getClass();

        System.out.println(sClass.isAssignableFrom(pClass));
        System.out.println(pClass.isAssignableFrom(sClass));

        // 获取构造函数，并打印构造函数的每一个参数
        Constructor<?>[] constructors = sClass.getConstructors();

        for (Constructor constructor : constructors) {
            Type[] types = constructor.getParameterTypes();
            for (Type type : types) {
                System.out.println(type.getTypeName());
            }
            System.out.println();
        }

        Class<Student> studentClass = Student.class;

        try {
            Constructor<Student> x = studentClass.getConstructor(Integer.class, String.class);

            Student student2 = x.newInstance(1, "dapeng");

            System.out.println(student2);


            Constructor<?>[] s = studentClass.getConstructors();

            for(Constructor<?> c : s) {
                Class<?>[] types = c.getParameterTypes();

                System.out.println(types);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
